// 原型模式
#include <iostream>
#include <string>
#include <string.h>

// 深拷贝，申请新的堆空间，拷贝数据
class Resume
{
private:
    int _age;

protected:
    char *_name;

public:
    Resume() {}
    ~Resume() {}
    virtual Resume *clone() { return NULL; }
    virtual void setName(const char *name) = 0;
};

class ResumeA : public Resume
{
private:
    /* data */
public:
    ResumeA() {}
    ResumeA(const ResumeA &r)
    {
        _name = new char[strlen(r._name) + 1];
        strcpy(_name, r._name);
    }
    ~ResumeA()
    {
        if (_name)
        {
            delete[] _name;
            _name = NULL;
        }
    }
    virtual void setName(const char *name)
    {
        if (name)
        {
            _name = new char[strlen(name) + 1];
            strcpy(_name, name);
        }
    }

    void display()
    {
        std::cout << Resume::_name << "\n";
    }

    ResumeA *clone()
    {
        return new ResumeA(*this);
    }
};

int main(int argc, char const *argv[])
{
    ResumeA *p0 = new ResumeA;
    p0->setName("jhon");
    p0->display();

    ResumeA *p1 = p0->clone();
    p1->setName("kkkk");
    p1->display();
    p0->display();
    return 0;
}
